package com.lance.answer.gui.answer.gk.answer.lms.batch;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.lance.answer.dto.CompleteInfo;
import com.lance.answer.gui.answer.gk.answer.lms.batch.dto.LmsWatchDTO;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.BatchLmsSaveVideoTask;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.LmsSaveVideoTask;
import com.lance.answer.gui.answer.gk.answer.lms.util.LmsUtil;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

public class BatchLmsSaveVideo {

    public static void main(String[] args) throws Exception {


     //   Thread.sleep(800*60*60*1);

        int sync = 2;

        LinkedBlockingDeque<LmsWatchDTO> watchQueue = new LinkedBlockingDeque<>();

        //    InputStream inputStream2 = new FileInputStream("libs//lms2022-x.user");
        //   InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all.user");
        InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all3.user");
        //     InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//李俊杰3.user");
        List<String> userString = IOUtils.readLines(inputStream2, "utf-8");

        for (String user : userString) {
            String[] strs = user.split(",");
            String userCode = strs[0];
            String pwd = strs[1];



            Map<Long, String> courseMap = LmsUtil.getUserCourseMap(userCode);
            if (null == courseMap) {
                continue;
            }

            for (long id : courseMap.keySet()) {
                String subjectName = courseMap.get(id);

                if (
                        subjectName.equals("习近平新时代中国特色社会主义思想")
                        || subjectName.equals("思想道德修养与法律基础")
                        || subjectName.equals("形势与政策")
                        || subjectName.equals("思想道德与法治")
                        || subjectName.equals("毛泽东思想和中国特色社会主义理论体系概论")
                        || subjectName.equals("中国近现代史纲要")
                        || subjectName.equals("马克思主义基本原理概论")
                        || subjectName.equals("马克思主义基本原理")
//                                ||subjectName.equals("国家开放大学学习指南")
//                                || subjectName.equals("计算机应用基础")
                ) {

                    LmsWatchDTO lmsWatchDTO = new LmsWatchDTO();
                    lmsWatchDTO.setUsername(userCode);
                    lmsWatchDTO.setPassword(pwd);
                    lmsWatchDTO.setCourseId(id);
                    lmsWatchDTO.setCourseName(subjectName);
                    watchQueue.add(lmsWatchDTO);
                }
            }


        }


        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new BatchLmsSaveVideoTask("d:\\ynouAutoStudy\\chromedriver.exe", watchQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName("答题线程--" + i);
            answerThread.start();
        }


    }


}
